
/* 获取圆上点的位置 */
function get_point_in_circle(center, radius, radian){	
    var x = center[0]+Math.cos(radian)*radius;
    var y = center[1]+Math.sin(radian)*radius;
    return [parseFloat(x.toFixed(4)),parseFloat(y.toFixed(4))];
    // return [x,y];
}

/*
功能：
    内外圆A和B，内圆A沿着外圆B的内圈滚动，已知外圆圆心、半径，已知内圆半径、公转弧度，已知绕点半径，计算绕点坐标
入参：
    center_A：外圆圆心
    radius_A：外圆半径
    radius_B：内圆半径
    radius_C：绕点半径
    radian：公转弧度
    clockwise:是否是顺时针
*/
function get_point_in_child_circle(center_A, radius_A, radius_B, radius_C, radian){
	// 计算内圆圆心坐标
    var center_B = get_point_in_circle(center_A, radius_A - radius_B, radian)
    // 计算绕点弧度（公转为逆时针，则自转为顺时针）
    if(clockwise){
    	var radian_C = (radius_A / radius_B * radian) % (2.0*Math.PI)
    }else{
    	var radian_C = 2.0*Math.PI - ((radius_A / radius_B * radian) % (2.0*Math.PI))
    }
    // 描点坐标
    var center_C = get_point_in_circle(center_B, radius_C, radian_C)

    return [center_B[0],center_B[1],center_C[0],center_C[1]]
}

// 两点距离（的平方）
function get_instance(p1, p2){
    return (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1])
}

function get_points(center_A, radius_A, radius_B, radius_C){

	var P2 = 2*Math.PI // 一圈的弧度为 2PI
    var R_PER_ROUND = parseInt(P2/shift_radian) + 1 // 一圈需要走多少步（弧度偏移多少次）

    var all_point = [];
    var point,s_radian,s_point

    for(i=0;i<100;i++){
        s_radian = P2 * i
        s_point = get_point_in_child_circle(center_A, radius_A, radius_B, radius_C, s_radian)
        if(get_instance(s_point[2],s_point[3]) < 0.1){
            break
        }

        for(j=0;j<R_PER_ROUND;j++){
            point = get_point_in_child_circle(center_A, radius_A, radius_B, radius_C, s_radian + j * shift_radian)
            all_point.push(point)
        }
    }
    console.log(all_point)
    return all_point
}

var shift_radian = 0.1;    //步距
var clockwise = true;       //是否顺时针
var start_redian = 99       //起始角度，（y轴正方向为0°）

var center_A = [150,150]        //圆心
var radius_A = 150          //外圆半径
var radius_B = 80           //内圆半径
var radius_C = 80           //描点半径


